<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id

	+ Module  		: m_unit View
	+ Description	: For record view
	+ Filename 		: v_m_unit.php
 	+ creator  		: 
 	+ Created on 24/Jul/2012 11:40:14

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */
var m_unit_DataStore;
var m_unit_ColumnModel;
var m_unit_ListEditorGrid;
var m_unit_saveForm;
var m_unit_searchForm;
var m_unit_searchWindow;
var m_unit_SelectedRow;
var m_unit_ContextMenu;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Batal";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Refresh";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Data Lanjut";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (html)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

/* declare variable here for Field*/
var unit_idField;
var unit_nameField;
var unit_activeField;
var unit_created_dateField;
var unit_created_byField;
var unit_updated_dateField;
var unit_updated_byField;
var unit_updated_countField;
/* For search form */
var unit_idSearchField;
var unit_nameSearchField;
var unit_activeSearchField;
var unit_created_dateSearchField;
var unit_created_bySearchField;
var unit_updated_dateSearchField;
var unit_updated_bySearchField;
var unit_updated_countSearchField;

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */

  	/* Function for Saving inLine Editing */
	function m_unit_inline_update(oGrid_event){

	var patt=new RegExp("U");
	if(patt.test(PERMISSION)==false){

		Ext.MessageBox.show({
		   title: 'Warning',
		   msg: FAILED_PERMISSION,
		   buttons: Ext.MessageBox.OK,
		   animEl: 'security',
		   icon: Ext.MessageBox.WARNING
		});

	}else{

		var unit_id_update_pk="";
		var unit_name_update=null;
		var unit_active_update=null;
		var unit_created_date_update_date="";
		var unit_created_by_update=null;
		var unit_updated_date_update_date="";
		var unit_updated_by_update=null;
		var unit_updated_count_update=null;

		unit_id_update_pk = oGrid_event.record.data.unit_id;
		if(oGrid_event.record.data.unit_name!== null){unit_name_update = oGrid_event.record.data.unit_name;}
		if(oGrid_event.record.data.unit_active!== null){unit_active_update = oGrid_event.record.data.unit_active;}
	 	/* if(oGrid_event.record.data.unit_created_date!== ""){unit_created_date_update_date =oGrid_event.record.data.unit_created_date.format('Y-m-d');}
		if(oGrid_event.record.data.unit_created_by!== null){unit_created_by_update = oGrid_event.record.data.unit_created_by;}
	 	if(oGrid_event.record.data.unit_updated_date!== ""){unit_updated_date_update_date =oGrid_event.record.data.unit_updated_date.format('Y-m-d');}
		if(oGrid_event.record.data.unit_updated_by!== null){unit_updated_by_update = oGrid_event.record.data.unit_updated_by;}
		if(oGrid_event.record.data.unit_updated_count!== null){unit_updated_count_update = oGrid_event.record.data.unit_updated_count;} */

		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_m_unit&m=get_action',
			params: {
				unit_id	: unit_id_update_pk,
				unit_name	:unit_name_update,
				unit_active	:unit_active_update,
				unit_created_date	: unit_created_date_update_date,
				unit_created_by	:unit_created_by_update,
				unit_updated_date	: unit_updated_date_update_date,
				unit_updated_by	:unit_updated_by_update,
				unit_updated_count	:unit_updated_count_update,
				task: "UPDATE"
			},
			success: function(response){
				var result=eval(response.responseText);
				switch(result){
					case 1:
						m_unit_DataStore.commitChanges();
						m_unit_DataStore.reload();
						break;
					default:
						Ext.MessageBox.show({
						   title: 'Warning',
						   msg: FAILED_SAVE,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'save',
						   icon: Ext.MessageBox.WARNING
						});
						break;
				}
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.show({
				   title: 'Error',
				   msg: FAILED_CONNECTION,
				   buttons: Ext.MessageBox.OK,
				   animEl: 'database',
				   icon: Ext.MessageBox.ERROR
				});
			}
		});

		}
	}
  	/* End of Function */

  	/* Function for add and edit data form, open window form */
	function m_unit_save(){

		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

		if(is_m_unit_form_valid()){
			var unit_id_field_pk=null;
			var unit_name_field=null;
			var unit_active_field=null;
			var unit_created_date_field_date="";
			var unit_created_by_field=null;
			var unit_updated_date_field_date="";
			var unit_updated_by_field=null;
			var unit_updated_count_field=null;

			unit_id_field_pk=get_pk_id();
			if(unit_nameField.getValue()!== null){unit_name_field = unit_nameField.getValue();}
			if(unit_activeField.getValue()!== null){unit_active_field = unit_activeField.getValue();}
			/* if(unit_created_dateField.getValue()!== ""){unit_created_date_field_date = unit_created_dateField.getValue().format('Y-m-d');}
			if(unit_created_byField.getValue()!== null){unit_created_by_field = unit_created_byField.getValue();}
			if(unit_updated_dateField.getValue()!== ""){unit_updated_date_field_date = unit_updated_dateField.getValue().format('Y-m-d');}
			if(unit_updated_byField.getValue()!== null){unit_updated_by_field = unit_updated_byField.getValue();}
			if(unit_updated_countField.getValue()!== null){unit_updated_count_field = unit_updated_countField.getValue();} */
			
			if(unit_activeField.getValue()!== null){unit_active_field = unit_activeField.items.get(0).getGroupValue();}
			
			
			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_m_unit&m=get_action',
				params: {
					unit_id	: unit_id_field_pk,
					unit_name	: unit_name_field,
					unit_active	: unit_active_field,
					unit_created_date	: unit_created_date_field_date,
					unit_created_by	: unit_created_by_field,
					unit_updated_date	: unit_updated_date_field_date,
					unit_updated_by	: unit_updated_by_field,
					unit_updated_count	: unit_updated_count_field,
					task: post2db
				},
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
							post2db = "CREATE";
							m_unit_DataStore.reload();
							m_unit_reset_form();
							break;
						default:
							Ext.MessageBox.show({
							   title: 'Warning',
							   msg: FAILED_SAVE,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'save',
							   icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					var result=response.responseText;
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			});

		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_VALID_FORM,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}

		}
	}
 	/* End of Function */

  	/* Function for get PK field */
	function get_pk_id(){
		if(post2db=='UPDATE')
			return m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_id');
		else
			return 0;
	}
	/* End of Function  */

	/* Reset form before loading */
	function m_unit_reset_form(){
		/* unit_idField.reset();
		unit_idField.setValue(null); */
		unit_nameField.reset();
		unit_nameField.setValue(null);
		unit_activeField.reset();
		unit_activeField.setValue(null);
		/* unit_created_dateField.reset();
		unit_created_dateField.setValue(null);
		unit_created_byField.reset();
		unit_created_byField.setValue(null);
		unit_updated_dateField.reset();
		unit_updated_dateField.setValue(null);
		unit_updated_byField.reset();
		unit_updated_byField.setValue(null);
		unit_updated_countField.reset();
		unit_updated_countField.setValue(null); */
	}
 	/* End of Function */

	/* setValue to EDIT */
	function m_unit_set_form(){
		/* unit_idField.setValue(m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_id')); */
		unit_nameField.setValue(m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_name'));
		unit_activeField.setValue(m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_active'));
		/* unit_created_dateField.setValue(m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_created_date'));
		unit_created_byField.setValue(m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_created_by'));
		unit_updated_dateField.setValue(m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_updated_date'));
		unit_updated_byField.setValue(m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_updated_by'));
		unit_updated_countField.setValue(m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_updated_count')); */
		
		if(m_unit_ListEditorGrid.getSelectionModel().getSelected().get('unit_active') == 'Y'){
			unit_activeField.setValue('unit_aktif', true);
		 }else{
			unit_activeField.setValue('unit_unaktif', true);
		 }
		
	}
	/* End setValue to EDIT*/

	/* Function for Check if the form is valid */
	function is_m_unit_form_valid(){
		return (unit_nameField.isValid() && unit_activeField.isValid());
	}
  	/* End of Function */

  	/* Function for Displaying  create Window Form */
	function display_form_window(){
			post2db='CREATE';
			msg='created';
			m_unit_reset_form();
	}
  	/* End of Function */

  	/* Function for Delete Confirm */
	function m_unit_confirm_delete(){
		// only one m_unit is selected here
		if(m_unit_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_DELETE, m_unit_delete);
		} else if(m_unit_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_MULTI_DELETE, m_unit_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_DELETE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */

	/* Function for Update Confirm */
	function m_unit_confirm_update(){
		/* only one record is selected here */
		if(m_unit_ListEditorGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			m_unit_set_form();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */

  	/* Function for Delete Record */
	function m_unit_delete(btn){
		if(btn=='yes'){

		var patt=new RegExp("D");
		if(patt.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

			var selections = m_unit_ListEditorGrid.selModel.getSelections();
			var prez = [];
			for(i = 0; i< m_unit_ListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.unit_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_m_unit&m=get_action',
				params: { task: "DELETE", ids:  encoded_array },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							m_unit_DataStore.reload();
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: FAILED_DELETE,
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					var result=response.responseText;
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

		}
	}
  	/* End of Function */

	/* Function for Retrieve DataStore */
	m_unit_DataStore = new Ext.data.Store({
		id: 'm_unit_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_m_unit&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'unit_id'
		},[
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'},
			{name: 'unit_active', type: 'string', mapping: 'unit_active'},
			{name: 'unit_created_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'unit_created_date'},
			{name: 'unit_created_by', type: 'string', mapping: 'unit_created_by'},
			{name: 'unit_updated_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'unit_updated_date'},
			{name: 'unit_updated_by', type: 'string', mapping: 'unit_updated_by'},
			{name: 'unit_updated_count', type: 'int', mapping: 'unit_updated_count'}
		]),
		sortInfo:{field: 'unit_id', direction: "DESC"}
	});
	/* End of Function */

  	/* Function for Identify of Window Column Model */
	m_unit_ColumnModel = new Ext.grid.ColumnModel(
		[
		{
			header: 'Id',
			dataIndex: 'unit_id',
			width: 150,
			sortable: true,
			hidden : true
		},
		{
			header: 'Nama',
			dataIndex: 'unit_name',
			width: 150,
			sortable: true
		},
		{
			header: 'Aktif',
			dataIndex: 'unit_active',
			width: 150,
			sortable: true
		},
		{
			header: 'Unit Created Date',
			dataIndex: 'unit_created_date',
			width: 150,
			sortable: true,
			renderer: Ext.util.Format.dateRenderer('Y-m-d'),
			hidden : true
		},
		{
			header: 'Unit Created By',
			dataIndex: 'unit_created_by',
			width: 150,
			sortable: true,
			hidden : true
		},
		{
			header: 'Unit Updated Date',
			dataIndex: 'unit_updated_date',
			width: 150,
			sortable: true,
			renderer: Ext.util.Format.dateRenderer('Y-m-d'),
			hidden : true
		},
		{
			header: 'Unit Updated By',
			dataIndex: 'unit_updated_by',
			width: 150,
			sortable: true,
			hidden : true
		},
		{
			header: 'Unit Updated Count',
			dataIndex: 'unit_updated_count',
			width: 150,
			sortable: true,
			hidden : true
		}	]);

	m_unit_ColumnModel.defaultSortable= true;
	/* End of Function */

    /* Button Control */
    m_unit_gbtn_add=new Ext.Button({
	    text: BTN_ADD_TITLE,
		tooltip: BTN_ADD_TOOLTIP,
		iconCls:'icon-adds',
		handler: display_form_window
    });

    m_unit_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: m_unit_confirm_update
	});

    m_unit_gbtn_delete=new Ext.Button({
	    text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: m_unit_confirm_delete
	});

    /*Context Menu Button */

	m_unit_cbtn_update=new Ext.menu.Item({
		text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: m_unit_editContextMenu
	});

	m_unit_cbtn_delete=new Ext.menu.Item({
		text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: m_unit_confirm_delete
	});

	/* Declare DataStore and  show datagrid list */
	m_unit_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 'm_unit_ListEditorGrid',
		el: 'fp_m_unit',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: m_unit_DataStore, // DataStore
		cm: m_unit_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
	  	width: 700,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: m_unit_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		m_unit_gbtn_add, '-',
		m_unit_gbtn_update, '-',
		m_unit_gbtn_delete, '-',
		/* {
			text: BTN_SEARCH_TITLE,
			tooltip: BTN_SEARCH_TOOLTIP,
			iconCls:'icon-search',
			handler: display_form_search_window
		}, '-', */
		new Ext.app.SearchField({
			store: m_unit_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						m_unit_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		})/*,'-',{
			text: BTN_REFRESH_TITLE,
			tooltip: BTN_REFERSH_TOOLTIP,
			handler: m_unit_reset_search,
			iconCls:'icon-refresh'
		},'-',{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: m_unit_export_excel
		}, '-',{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: m_unit_print
		}*/
		]
	});
	m_unit_ListEditorGrid.render();
	/* End of DataStore */

	/* Create Context Menu */
	m_unit_ContextMenu = new Ext.menu.Menu({
		id: 'm_unit_ContextMenu',
		items: [
		m_unit_cbtn_update,
		m_unit_cbtn_delete,
		'-',
		{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: m_unit_print
		},
		{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: m_unit_export_excel
		}
		]
	});
	/* End of Declaration */

	/* Event while selected row via context menu */
	function onm_unit_ContextMenu(grid, rowIndex, e) {
		e.stopEvent();
		var coords = e.getXY();
		m_unit_ContextMenu.rowRecord = grid.store.getAt(rowIndex);
		grid.selModel.selectRow(rowIndex);
		m_unit_SelectedRow=rowIndex;
		m_unit_ContextMenu.showAt([coords[0], coords[1]]);
  	}
  	/* End of Function */

	/* function for editing row via context menu */
	function m_unit_editContextMenu(){
		//m_unit_ListEditorGrid.startEditing(m_unit_SelectedRow,1);
		m_unit_confirm_update();
  	}
	/* End of Function */

	m_unit_ListEditorGrid.addListener('rowcontextmenu', onm_unit_ContextMenu);
	m_unit_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
	m_unit_ListEditorGrid.on('afteredit', m_unit_inline_update); // inLine Editing Record

	unit_idField= new Ext.form.NumberField({
		id: 'unit_idField',
		fieldLabel: 'Unit Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	unit_nameField= new Ext.form.TextField({
		id: 'unit_nameField',
		fieldLabel: 'Nama ',
		maxLength: 45,
		anchor: '95%'
	});
	/* unit_activeField= new Ext.form.TextField({
		id: 'unit_activeField',
		fieldLabel: 'Aktif ',
		maxLength: 1,
		anchor: '95%'
	}); */
	
	unit_activeField = new Ext.form.RadioGroup({
		fieldLabel : 'Aktif',
		id : 'unit_activeField',
		width : 150,
		defaults : {xtype : 'radio', name : 'unit_activeField'},
		items : [
			{
				boxLabel : 'Ya',
				inputValue : 'Y',
				checked : true,
				id : 'unit_aktif'
			},
			{
				boxLabel : 'Tidak',
				inputValue : 'T',
				id : 'unit_unaktif'
			}
		]
	});
	
	unit_created_dateField= new Ext.form.DateField({
		id: 'unit_created_dateField',
		fieldLabel: 'Created Date ',
		format : 'Y-m-d',
		anchor: '95%'
	});
	unit_created_byField= new Ext.form.TextField({
		id: 'unit_created_byField',
		fieldLabel: 'Created By ',
		maxLength: 45,
		anchor: '95%'
	});
	unit_updated_dateField= new Ext.form.DateField({
		id: 'unit_updated_dateField',
		fieldLabel: 'Updated Date ',
		format : 'Y-m-d',
		anchor: '95%'
	});
	unit_updated_byField= new Ext.form.TextField({
		id: 'unit_updated_byField',
		fieldLabel: 'Updated By ',
		maxLength: 45,
		anchor: '95%'
	});
	unit_updated_countField= new Ext.form.NumberField({
		id: 'unit_updated_countField',
		fieldLabel: 'Updated Count ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});


	m_unit_btn_Save=new Ext.Button({
		text: BTN_SAVE,
		handler: m_unit_save
	})
	/* Function for retrieve create Window Panel*/
	m_unit_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' Unit',
		bodyStyle:'padding:5px',
		autoHeight:true,
		layout:'form',
		width: 500,
		collapsible: true,
		frame: true,
		renderTo: 'elwindow_m_unit_save',
		items:[/* unit_idField, */
			   unit_nameField,
			   unit_activeField,
			   /* unit_created_dateField,
			   unit_created_byField,
			   unit_updated_dateField,
			   unit_updated_byField,
			   unit_updated_countField, */
			   new  Ext.form.Label({html:'Keterangan : <font color=red>*</font>  '+INFO_REQUIRED })
		],
		buttons: [m_unit_btn_Save
			,{
				text: BTN_CANCEL,
				handler: function(){
					m_unit_reset_form();
				}
			}
		]
	});
	/* End  of Function*/


	/* Function for action list search */
	function m_unit_list_search(){

		var unit_id_search=null;
		var unit_name_search=null;
		var unit_active_search=null;
		var unit_created_date_search_date="";
		var unit_created_by_search=null;
		var unit_updated_date_search_date="";
		var unit_updated_by_search=null;
		var unit_updated_count_search=null;

		/* if(unit_idSearchField.getValue()!==null){unit_id_search=unit_idSearchField.getValue();} */
		if(unit_nameSearchField.getValue()!==null){unit_name_search=unit_nameSearchField.getValue();}
		if(unit_activeSearchField.getValue()!==null){unit_active_search=unit_activeSearchField.getValue();}
		/* if(unit_created_dateSearchField.getValue()!==""){unit_created_date_search_date=unit_created_dateSearchField.getValue().format('Y-m-d');}
		if(unit_created_bySearchField.getValue()!==null){unit_created_by_search=unit_created_bySearchField.getValue();}
		if(unit_updated_dateSearchField.getValue()!==""){unit_updated_date_search_date=unit_updated_dateSearchField.getValue().format('Y-m-d');}
		if(unit_updated_bySearchField.getValue()!==null){unit_updated_by_search=unit_updated_bySearchField.getValue();}
		if(unit_updated_countSearchField.getValue()!==null){unit_updated_count_search=unit_updated_countSearchField.getValue();} */

		m_unit_DataStore.baseParams = {
			task: 'SEARCH',
			unit_id	:	unit_id_search,
			unit_name	:	unit_name_search,
			unit_active	:	unit_active_search,
			unit_created_date	:	unit_created_date_search_date,
			unit_created_by	:	unit_created_by_search,
			unit_updated_date	:	unit_updated_date_search_date,
			unit_updated_by	:	unit_updated_by_search,
			unit_updated_count	:	unit_updated_count_search
		};

		m_unit_DataStore.reload({params: {start: 0, limit: pageS}});
	}

	/* Function for reset search result */
	function m_unit_reset_search(){
		m_unit_DataStore.baseParams = { task: 'LIST' };
		m_unit_DataStore.reload({params: {start: 0, limit: pageS}});
		//m_unit_searchWindow.close();
	};
	/* End of Fuction */

	/* Field for search */
	/* Identify  unit_id Search Field */
	unit_idSearchField= new Ext.form.NumberField({
		id: 'unit_idSearchField',
		fieldLabel: 'Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  unit_name Search Field */
	unit_nameSearchField= new Ext.form.TextField({
		id: 'unit_nameSearchField',
		fieldLabel: 'Nama',
		maxLength: 45,
		anchor: '95%'
	});
	/* Identify  unit_active Search Field */
	unit_activeSearchField= new Ext.form.TextField({
		id: 'unit_activeSearchField',
		fieldLabel: 'Aktif',
		maxLength: 1,
		anchor: '95%'
	});
	/* Identify  unit_created_date Search Field */
	unit_created_dateSearchField= new Ext.form.DateField({
		id: 'unit_created_dateSearchField',
		fieldLabel: 'Created Date',
		format : 'Y-m-d'
	});
	/* Identify  unit_created_by Search Field */
	unit_created_bySearchField= new Ext.form.TextField({
		id: 'unit_created_bySearchField',
		fieldLabel: 'Created By',
		maxLength: 45,
		anchor: '95%'
	});
	/* Identify  unit_updated_date Search Field */
	unit_updated_dateSearchField= new Ext.form.DateField({
		id: 'unit_updated_dateSearchField',
		fieldLabel: 'Updated Date',
		format : 'Y-m-d'
	});
	/* Identify  unit_updated_by Search Field */
	unit_updated_bySearchField= new Ext.form.TextField({
		id: 'unit_updated_bySearchField',
		fieldLabel: 'Updated By',
		maxLength: 45,
		anchor: '95%'
	});
	/* Identify  unit_updated_count Search Field */
	unit_updated_countSearchField= new Ext.form.NumberField({
		id: 'unit_updated_countSearchField',
		fieldLabel: 'Updated Count',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});

	/* Function for retrieve search Form Panel */
	m_unit_searchForm = new Ext.FormPanel({
		labelAlign: 'left',
		layout:'form',
		bodyStyle:'padding:5px',
		autoHeight:true,
		frame: true,
		width: 500,
		items: [/* unit_idSearchField, */
				unit_nameSearchField,
				unit_activeSearchField,
				/* unit_created_dateSearchField,
				unit_created_bySearchField,
				unit_updated_dateSearchField,
				unit_updated_bySearchField,
				unit_updated_countSearchField */
		 ],
		buttons: [{
				text: BTN_SEARCH,
				handler: m_unit_list_search
			},{
				text: BTN_CANCEL,
				handler: function(){
					m_unit_searchWindow.hide();
				}
			}
		]
	});
    /* End of Function */

	/* Function for retrieve search Window Form, used for andvaced search */
	m_unit_searchWindow = new Ext.Window({
		title: TITLE_FORM_SEARCH+' Unit',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		plain:true,
		layout: 'fit',
		x: 0,
		y: 0,
		modal: true,
		renderTo: 'elwindow_m_unit_search',
		items: m_unit_searchForm
	});
    /* End of Function */

  	/* Function for Displaying  Search Window Form */
	function display_form_search_window(){
		if(!m_unit_searchWindow.isVisible()){
			m_unit_searchWindow.show();
		} else {
			m_unit_searchWindow.toFront();
		}
	}
  	/* End Function */

	/* Function for print List Grid */
	function m_unit_print(){
		var searchquery = "";
		var unit_id_print=null;
		var unit_name_print=null;
		var unit_active_print=null;
		var unit_created_date_print_date="";
		var unit_created_by_print=null;
		var unit_updated_date_print_date="";
		var unit_updated_by_print=null;
		var unit_updated_count_print=null;

		if(m_unit_DataStore.baseParams.query!==null){searchquery = m_unit_DataStore.baseParams.query;}
		if(m_unit_DataStore.baseParams.unit_id!==null){unit_id_print = m_unit_DataStore.baseParams.unit_id;}
		if(m_unit_DataStore.baseParams.unit_name!==null){unit_name_print = m_unit_DataStore.baseParams.unit_name;}
		if(m_unit_DataStore.baseParams.unit_active!==null){unit_active_print = m_unit_DataStore.baseParams.unit_active;}
		/* if(m_unit_DataStore.baseParams.unit_created_date!==""){unit_created_date_print_date = m_unit_DataStore.baseParams.unit_created_date;}
		if(m_unit_DataStore.baseParams.unit_created_by!==null){unit_created_by_print = m_unit_DataStore.baseParams.unit_created_by;}
		if(m_unit_DataStore.baseParams.unit_updated_date!==""){unit_updated_date_print_date = m_unit_DataStore.baseParams.unit_updated_date;}
		if(m_unit_DataStore.baseParams.unit_updated_by!==null){unit_updated_by_print = m_unit_DataStore.baseParams.unit_updated_by;}
		if(m_unit_DataStore.baseParams.unit_updated_count!==null){unit_updated_count_print = m_unit_DataStore.baseParams.unit_updated_count;} */

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_m_unit&m=get_action',
		params: {
			task: "PRINT",
		  	query: searchquery,
			unit_id : unit_id_print,
			unit_name : unit_name_print,
			unit_active : unit_active_print,
		  	unit_created_date : unit_created_date_print_date,
			unit_created_by : unit_created_by_print,
		  	unit_updated_date : unit_updated_date_print_date,
			unit_updated_by : unit_updated_by_print,
			unit_updated_count : unit_updated_count_print,
		  	currentlisting: m_unit_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				window.open('./print/m_unit_printlist.html','m_unitlist','height=600,width=800,resizable=1,scrollbars=0, menubar=0');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_PRINT,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	/* Enf Function */

	/* Function for print Export to Excel Grid */
	function m_unit_export_excel(){
		var searchquery = "";
		var unit_id_2excel=null;
		var unit_name_2excel=null;
		var unit_active_2excel=null;
		var unit_created_date_2excel_date="";
		var unit_created_by_2excel=null;
		var unit_updated_date_2excel_date="";
		var unit_updated_by_2excel=null;
		var unit_updated_count_2excel=null;

		if(m_unit_DataStore.baseParams.query!==null){searchquery = m_unit_DataStore.baseParams.query;}
		if(m_unit_DataStore.baseParams.unit_id!==null){unit_id_2excel = m_unit_DataStore.baseParams.unit_id;}
		if(m_unit_DataStore.baseParams.unit_name!==null){unit_name_2excel = m_unit_DataStore.baseParams.unit_name;}
		if(m_unit_DataStore.baseParams.unit_active!==null){unit_active_2excel = m_unit_DataStore.baseParams.unit_active;}
		/* if(m_unit_DataStore.baseParams.unit_created_date!==""){unit_created_date_2excel_date = m_unit_DataStore.baseParams.unit_created_date;}
		if(m_unit_DataStore.baseParams.unit_created_by!==null){unit_created_by_2excel = m_unit_DataStore.baseParams.unit_created_by;}
		if(m_unit_DataStore.baseParams.unit_updated_date!==""){unit_updated_date_2excel_date = m_unit_DataStore.baseParams.unit_updated_date;}
		if(m_unit_DataStore.baseParams.unit_updated_by!==null){unit_updated_by_2excel = m_unit_DataStore.baseParams.unit_updated_by;}
		if(m_unit_DataStore.baseParams.unit_updated_count!==null){unit_updated_count_2excel = m_unit_DataStore.baseParams.unit_updated_count;} */

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_m_unit&m=get_action',
		params: {
			task: "EXCEL",
		  	query: searchquery,
			unit_id : unit_id_2excel,
			unit_name : unit_name_2excel,
			unit_active : unit_active_2excel,
		  	unit_created_date : unit_created_date_2excel_date,
			unit_created_by : unit_created_by_2excel,
		  	unit_updated_date : unit_updated_date_2excel_date,
			unit_updated_by : unit_updated_by_2excel,
			unit_updated_count : unit_updated_count_2excel,
		  	currentlisting: m_unit_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
		  		window.open('./print/m_unit_printlist.xls');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_EXCEL,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	/*End of Function */

	/* Show Hide control for permission */
	var pattr=new RegExp("R");
	var pattc=new RegExp("C");
	var pattu=new RegExp("U");
	var pattd=new RegExp("D");

	if(pattc.test(PERMISSION)==false){
		m_unit_gbtn_add.setVisible(false);
	}else{
		m_unit_gbtn_add.setVisible(true);
	}

	if(pattu.test(PERMISSION)==false){
		m_unit_gbtn_update.setVisible(false);
		m_unit_cbtn_update.setVisible(false);
	}else{
		m_unit_gbtn_update.setVisible(true);
		m_unit_cbtn_update.setVisible(true);
	}

	if(pattd.test(PERMISSION)==false){
		m_unit_gbtn_delete.setVisible(false);
		m_unit_cbtn_delete.setVisible(false);
	}else{
		m_unit_gbtn_delete.setVisible(true);
		m_unit_cbtn_delete.setVisible(true);
	}

	if(pattc.test(PERMISSION)==false && pattu.test(PERMISSION)==false){
		m_unit_btn_Save.setVisible(false);
	}else{
		m_unit_btn_Save.setVisible(true);
	}
});
	</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="elwindow_m_unit_save"></div>
		<div>&nbsp;</div>
		<div id="fp_m_unit"></div>
        <div id="elwindow_m_unit_search"></div>
    </div>
</div>
</body>
</html>